<?php
//#########INCLUDE FILES########
include_once '../conf/db-config.php';
include_once '../conf/error.php';
include_once '../clsFetchData.php';
include_once '../array_to_xml.php';
//##############################

//$xml = simplexml_load_file("global_to_do_category_listing_for_feed.xml");
$xml = simplexml_load_file("http://globaltodo.com/xmlcontact/admin/global_to_do_category_listing_for_feed.xml");
$xmlarray = array(); 
function xmlToArray($input, $callback = null, $recurse = false) {
	 $data = ((!$recurse) && is_string($input))? simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA): $input;
	 if ($data instanceof SimpleXMLElement) $data = (array) $data;
	 if (is_array($data)) foreach ($data as &$item) $item = xmlToArray($item, $callback, true);
	 return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;
	}

$xmlarray = xmlToArray($xml);
$arrIdSlNo = array();
$count=0;
if(is_array($xmlarray) && count($xmlarray)>0)
{
	mysql_query("TRUNCATE table tbl_city_names");
}
$cityArr = array();
foreach($xmlarray as $key=>$val)
{
	foreach ($val as $keys=>$vals)
	{
		if($key=="city")
		{
			$vals = strtolower($vals);
			array_push($cityArr,$vals);
		}
	}
}
$unqueCityArr=array();
if(count($cityArr)>0)
{
	$unqueCityArr = array_unique($cityArr);
}
$count =0;
foreach ($unqueCityArr as $keyCity=>$valCity)
{
	$count++;
	mysql_query("INSERT INTO tbl_city_names (id,city_name) VALUES ($count,'$valCity')");
}

?> 